pp108 : add Method (Dropdown)

add Method (Dropdown)


This method adds an option to the drop-down menu or list.

Syntax

HTML

var oAddedElement = controlID.add(vItem, sValue)


Parameters

Parameter

Description

vItem

Required. String or object that denotes the option to be added. If this is a string then this will be the name if the option added. If vItem is a DIV object then it is added as an option.

sValue

Optional. String with the value of the option to be added.


Return Value


Returns the option that is newly added to the component.

Example


The following example shows how this method is used to add an item to the combo box.

//JScript function to add item to combo box
function addItem()
{
    //The name of the dropdown box is 'myDropdown'
    myDropdown.add("New Item", "New Value");
    //Create a DIV element and pass an object as input
    var newItem = window.document.createElement("DIV");
    newItem.innerHTML = "New Item";
    newItem.value = "New Value";
    //Add the new item
    myDropdown.add(newItem);
}

See Also


Dropdown, ListBox